<?php

require_once(DIR_LIB."VsGui".DIR_SEP."vssmarty.php");

class VsSmartyWidget {

	private $_smarty = NULL;

	protected $_wwwDir = '';
	protected $_tplDir = '';

	protected $_template = '';

	protected $_jsCode = '';
	protected $_cssCode = '';

	function setTemplate($template) {
		$this->_template = $template;
	}
	//================================================================================

	function show() {
		//if(isExists($this->_template))

		// Only For Example
		//$this->repairDelimiterConflicts();
		$this->assign('jsCode', $this->_jsCode);
		$this->assign('cssCode', $this->_cssCode);

		return $this->_smarty->fetch($this->_template);
	}
	//=============================================================================

	protected function __construct() {
		$this->_smarty = VsSmarty::Instance();

		//$this->_smarty = new VsSmarty;
	}
	//============================================================================

	protected function assign($var, $value) {
		$this->_smarty->assign($var, $value);
	}
	//=============================================================================

	protected function fetch($template) {
		//echo "VsSmartyWidget::fetch()";

		return $this->_smarty->fetch($template);
	}
	//=============================================================================

	protected function display($template) {
		$this->_smarty->display($template);
	}
	//=============================================================================

	protected function repairDelimiterConflicts() {
		if(($this->_jsCode == '') && ($this->_cssCode == ''))
			return;

		if(($this->_smarty->left_delimiter === '{') && ($this->_smarty->right_delimiter === '}')) {
			$this->_jsCode = str_replace('{', '{$smarty.ldelim}', $this->_jsCode);
			$this->_jsCode = str_replace('}', '{$smarty.rdelim}', $this->_jsCode);
			$this->_cssCode = str_replace('{', '{$smarty.ldelim}', $this->_cssCode);
			$this->_cssCode = str_replace('}', '{$smarty.rdelim}', $this->_cssCode);
		}
	}
	//==============================================================================

};

?>
